package io.gitee.crud.converter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.gitee.crud.model.dto.DemoUserDTO;
import io.gitee.crud.model.dto.UserDeleteDTO;
import io.gitee.crud.model.dto.DemoUserSaveDTO;
import io.gitee.crud.model.dto.DemoUserUpdateDTO;
import io.gitee.crud.model.entity.DemoUserEntity;
import io.gitee.crud.model.vo.DemoUserVO;
import io.gitee.crud.common.PageResult;

import java.util.Collections;
import java.util.List;

public class DemoUserConverter {

    public static DemoUserEntity toEntity(DemoUserSaveDTO dto) {
        DemoUserEntity entity = new DemoUserEntity();
        entity.setUsername(dto.getUsername());
        entity.setDept(dto.getDept());
        return entity;
    }

    public static List<Long> toEntity(UserDeleteDTO dto) {
        return dto.getIds();
    }

    public static DemoUserEntity toEntity(DemoUserUpdateDTO dto) {
        DemoUserEntity entity = new DemoUserEntity();
        entity.setId(dto.getId());
        entity.setDept(dto.getDept());
        return entity;
    }

    public static List<DemoUserEntity> toEntity(List<DemoUserDTO> dtoList) {
        return Collections.emptyList();
    }

    public static PageResult<DemoUserVO> toPageResult(IPage<DemoUserEntity> page) {
        return PageResult.of(page.convert(DemoUserConverter::toVO));
    }

    private static DemoUserVO toVO(DemoUserEntity demoUserEntity) {
        DemoUserVO VO = new DemoUserVO();
        VO.setId(demoUserEntity.getId());
        VO.setUsername(demoUserEntity.getUsername());
        VO.setDept(demoUserEntity.getDept());
        return VO;
    }
}
